package com.acyouzi.dj;

import java.util.*;

/**
 * 17/9/12 22:05
 *
 * @author sunxu
 */
public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int len = in.nextInt();
    Map<Integer,List<Integer>> map = new HashMap<>();
    map.put(1,new ArrayList<>());
    for (int i = 0; i < len-1; i++) {
      int id = in.nextInt();
      int p_id = in.nextInt();
      int pos = in.nextInt();
      if (map.containsKey(p_id)){
        map.get(p_id).add(id);
      }else {
        List<Integer> list = new ArrayList<>();
        list.add(id);
        map.put(p_id,list);
      }
      if (!map.containsKey(id)){
        map.put(id,new ArrayList<>());
      }
    }
    int flag = in.nextInt();
    int res = 0;
    Queue<Integer> queue = new ArrayDeque<>();
    queue.add(flag);
    while (!queue.isEmpty()){
      int tmp = queue.poll();
      if (map.containsKey(tmp)){
        ++ res;
        for (int i : map.get(tmp)) queue.add(i);
      }
    }
    System.out.println(res);
  }
}
